package com.ssy.lingxi.scheduler.api.handler.validator;

import com.ssy.lingxi.scheduler.api.handler.annotation.TimestampAnnotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Unix时间戳校验注解校验类
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-12
 */
public class TimestampValidator  implements ConstraintValidator<TimestampAnnotation, Long> {

    private boolean nullable = false;

    @Override
    public void initialize(TimestampAnnotation constraintAnnotation) {
        nullable = constraintAnnotation.nullable();
    }

    @Override
    public boolean isValid(Long value, ConstraintValidatorContext context) {
        if(value == null) {
            return nullable;
        }

        return value > System.currentTimeMillis();
    }
}
